home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / programmers / source / chunky / dump.c < prev    next >
C/C++ Source or Header  |  1978-06-29  |  3KB  |  148 lines

  1. /* based on tmapdemo/dumpchunky.c, but made more useful ;-) */
  2.  
  3. #include <stdio.h>
  4.  
  5. FILE *fout=0;
  6.  
  7. #include <exec/types.h>
  8. #include <clib/exec_protos.h>
  9. #include <graphics/view.h>
  10. #include <graphics/rastport.h>
  11.     /*#include <intuition/intuition.h>    Hey guys, let's use the
  12.     #include <intuition/screens.h>        correct includes ;-)    */
  13. #include <stdio.h>
  14. #define NO_PRAGMAS 1
  15. /*#include "pd:ifflib/iff.h"*/
  16.  
  17. struct IFFL_BMHD {    /* i'm guessing here - i don't have the includes... */
  18.     UWORD w,h;
  19.     WORD x,y;
  20.     UBYTE nPlanes,masking,compression,pad1;
  21.     UWORD transparentColor;
  22.     UBYTE xAspect,yAspect;
  23.     WORD pageWidth,pageHeight;
  24.     };
  25. #define ID_CMAP 0x434d4150        /* and here too */
  26.  
  27. #pragma libcall IFFBase OpenIFF 1e 801
  28. #pragma libcall IFFBase CloseIFF 24 901
  29. #pragma libcall IFFBase FindChunk 2a 902
  30. #pragma libcall IFFBase GetBMHD 30 901
  31. #pragma libcall IFFBase GetColorTab 36 8902
  32. #pragma libcall IFFBase DecodePic 3c 8902
  33. #pragma libcall IFFBase SaveBitMap 42 a9804
  34. /*#pragma libcall IFFBase SaveClip 48 210a9808*/
  35. #pragma libcall IFFBase IFFError 4e 0
  36. #pragma libcall IFFBase GetViewModes 54 901
  37. #pragma libcall IFFBase NewOpenIFF 5a 802
  38. #pragma libcall IFFBase ModifyFrame 60 8902
  39.  
  40. struct Library *GfxBase,*IntuitionBase,*IFFBase;
  41. struct BitMap *mybitmap;
  42. ULONG *infile;
  43.  
  44. void Fail(char *msg)
  45. {
  46.     if (fout) fclose(fout);
  47.     if (msg) printf("%s\n",msg);
  48.     if (mybitmap) FreeBitMap(mybitmap);
  49.     if (GfxBase) CloseLibrary(GfxBase);
  50.     if (infile) CloseIFF(infile);
  51.     if (IFFBase) CloseLibrary(IFFBase);
  52.     exit(0);
  53. }
  54.  
  55.  
  56. struct Library *openlib(char *name,ULONG version)
  57. {
  58.     struct Library *t1;
  59.     t1=OpenLibrary(name,version);
  60.     if (! t1)
  61.     {
  62.         printf("error- needs %s version %d\n",name,version);
  63.         Fail(0l);
  64.     }
  65.     else return(t1);
  66. }
  67.  
  68.  
  69.  
  70. UWORD cmap[256];
  71.  
  72. struct RastPort myrp;
  73.  
  74. main(argc,argv)
  75. int argc;
  76. char **argv;
  77. {
  78.     GfxBase=openlib("graphics.library",39);
  79.     IFFBase=openlib("iff.library",0);
  80.     if (argc==3)
  81.     {
  82.     if (fout=fopen(argv[2],"wb"))
  83.      {
  84.         if (infile=OpenIFF(argv[1]))
  85.         {
  86.             ULONG scrwidth,scrheight,scrdepth;
  87.             ULONG i,j;
  88.             struct IFFL_BMHD *bmhd;
  89.  
  90.             ULONG *form,*chunk;
  91.             ULONG count;
  92.             UBYTE *ptr;
  93.  
  94.             chunk=FindChunk(infile,ID_CMAP);
  95.             if (! chunk) Fail("no color table");
  96.             chunk++;
  97.             count=(*(chunk++))/3;
  98.             ptr=chunk;
  99.             if (count>256) count=256;
  100.  
  101.             for(i=0;i<count;i++)
  102.                 cmap[i]=(((*ptr++)&0xf0)<<4)|((*ptr++)&0xf0)|(((*ptr++)&0xf0)>>4);
  103.  
  104.             if(!(bmhd=GetBMHD(infile))) Fail("BitMapHeader not found");
  105.             InitRastPort(&myrp);
  106.  
  107.             scrwidth = bmhd->w;
  108.             scrheight = bmhd->h;
  109.             scrdepth = bmhd->nPlanes;
  110.             mybitmap=AllocBitMap(scrwidth,scrheight,scrdepth,BMF_CLEAR,0l);
  111.             if (! mybitmap) Fail("no bitmap");
  112.             if(!DecodePic(infile,mybitmap)) Fail("Can't decode picture");
  113.             myrp.BitMap=mybitmap;
  114.             for(i=0;i<scrwidth;i++)
  115.                 for(j=0;j<scrheight;j++)
  116.                     outb(ReadPixel(&myrp,i,j));
  117.  
  118.             flbuf();
  119.             Fail(0);
  120.         }
  121.      }
  122.     }
  123. }
  124.  
  125. #define BUFSZ 4096
  126.  
  127. UWORD buffer[BUFSZ];
  128.  
  129. int curout=0;
  130.  
  131. outb(c)
  132. {
  133.     buffer[curout++]=cmap[c];
  134.     if (curout==BUFSZ)
  135.         {
  136.         if (curout!=fwrite(&buffer[0],sizeof(buffer[0]),curout,fout))
  137.             Fail("cannot write data");
  138.         curout=0;
  139.         }
  140. }
  141.  
  142. flbuf()
  143. {
  144. if (curout!=fwrite(&buffer[0],sizeof(buffer[0]),curout,fout))
  145.     Fail("cannot write data");
  146. curout=0;
  147. }
  148.